# coding:utf-8
"""
description:执行测试
"""
import os
import time
import unittest

from BeautifulReport import BeautifulReport

from common import Send_Mail
from common.Get_Emailpwdcode import get_emailcontent
from config.GlobalParameter import test_case_path, TEST_Element_YAML, report_path

# 构建测试集,包含src/test_case目录下的所有以test开头的.py文件
suite = unittest.defaultTestLoader.discover(start_dir=test_case_path,pattern='test_*.py',top_level_dir=None)

# 执行测试
if __name__=="__main__":
    # print(get_emailcontent())
    """
     打印到控制台
    """
    # unittest.TextTestRunner(verbosity=2).run(suite)
    """
     BeautifulReport输出测试报告
    """
    run=BeautifulReport(suite)
    filenames=" kyla ui automated testing "+time.strftime('%Y%m%d%H%M%S', time.localtime())
    run.report(report_dir=report_path,filename=filenames,description='Android app项目')

    """
     HTMLTestRunner输出测试报告
    """
    # report = report_name+"Report.html"
    # fb = open(report,'wb')
    # runner = HTMLTestRunner.HTMLTestRunner(
    #     stream=fb,
    #     title=u'KylaAPP自动化测试报告',
    #     description=u'项目描述'
    # )
    # runner.run(suite) # 打印到报告
    # fb.close()

    # """发送邮件"""
    # time.sleep(10)  # 设置睡眠时间，等待测试报告生成完毕
    # email = Send_Mail.send_email()
    # email.sendReport()